package page.Beans;

import java.sql.SQLException;

import db.RADAO;
import basicTypes.RAClient;

public class loginBean {
	private login logado;
	private RAClient user;
	private RADAO bd;
	
	public loginBean() throws SQLException{
		logado = new login();
		bd = (RADAO) RADAO.getInstance();
	}
	
	public String logar() throws SQLException{
		String user = logado.getUsuario();
		String senha = logado.getSenha();
		try{
		this.user = bd.login(user, senha);
		}
		catch(NullPointerException e){
			user = null;
		}
		String result;
		
		if(this.user==null)
			result = "fail";
		else if(this.user.isAdmin())
			result = "adm";
		else
			result = "user";
		
		
		return result;
	}

	public login getLogado() {
		return logado;
	}

	public void setLogado(login logado) {
		this.logado = logado;
	}

	public RAClient getUser() {
		return user;
	}

	public void setUser(RAClient user) {
		this.user = user;
	}

	public RADAO getBd() {
		return bd;
	}

	public void setBd(RADAO bd) {
		this.bd = bd;
	}
	
	
	
	
}
